﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcs.Web.DemandPlan
{
    public partial class BidResultCheck : System.Web.UI.Page
    {
        Maticsoft.BLL.supplier_bidplan_order sm = new Maticsoft.BLL.supplier_bidplan_order();
        Maticsoft.BLL.workFlow wm = new Maticsoft.BLL.workFlow();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        //审核通过
        protected void btn_yes_Click(object sender, EventArgs e)
        {
            if (Session["supplier_bidplan_order"] != null)
            {
                //插入中标情况表数据
                List<Maticsoft.Model.supplier_bidplan_order> l = Session["supplier_bidplan_order"] as List<Maticsoft.Model.supplier_bidplan_order>;

                if (l.Count > 0)
                {
                    #region 插入下一流程

                    //插入下一流程数据
                    int dpid = l[0].dpid.Value;

                    #region
                    //List<Maticsoft.Model.documentFlowInfo> li = new Maticsoft.BLL.documentFlowInfo().GetModelList(" document_id = " + dpid);

                    //if (li.Count == 1)
                    //{
                    //    Maticsoft.Model.documentFlowInfo d = li[0];

                    //    string reason = "同意";

                    //    int person_id = 0;
                    //    if (Session["login"] != null)
                    //    {
                    //        DataSet ds = Session["login"] as DataSet;

                    //        person_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"]);
                    //    }

                    //    //获取当前审批人审批节点号，transfer的undefine4记录的是该由哪个审批人审批的节点号，如果要修改自身的workFlow，则节点号就是undefine4
                    //    int flow_node_num_now = Convert.ToInt32(d.flow_node_num_now);
                    //    int flow_node_id_now = 0;

                    //    flow_node_id_now = wm.GetFlow_node_id_now(person_id, d.document_id.Value, flow_node_num_now);

                    //    if (wm.UpdateW(person_id, d.document_id.Value, 1, reason, DateTime.Now, flow_node_id_now, flow_node_num_now))//修改本身意见为同意,添加处理意见、处理时间
                    //    {
                    //        int flow_node_id = wm.GetFlow_node_id(person_id, d.document_id.Value, Convert.ToInt32(d.flow_node_num_now));

                    //        string str = wm.Submit_judge(flow_node_id, person_id, d.document_id.Value, Convert.ToInt32(d.flow_node_num_now));//得到审核状态

                    //        if (str == "同意")//1、如果是会签非尾节点同意，插入下一节点
                    //        {
                    //            lcs.BLL.Tools.DealWorkFlow(d, flow_node_id, person_id);

                    //        }

                    //        if (str == "尾节点同意")//2、如果是会签尾节点同意
                    //        {
                    //            lcs.BLL.Tools.DealLast(d, person_id);

                    //        }

                    //        if (str == "非会签")//3、如果是非会签非尾节点，插入下一结点
                    //        {
                    //            lcs.BLL.Tools.DealWorkFlow(d, flow_node_id, person_id);
                    //        }

                    //        if (str == "尾节点非会签")
                    //        {
                    //            lcs.BLL.Tools.DealLast(d, person_id);
                    //        }
                    //    }

                    //    Response.Redirect("ListBidResultSubmit.aspx");
                    //}
                    #endregion

                    string reason = this.txt_reason.Text;

                    if (string.IsNullOrEmpty(reason))
                    {
                        reason = "同意";
                    }


                    int person_id = 0;
                    if (Session["login"] != null)
                    {
                        DataSet ds = Session["login"] as DataSet;

                        person_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"]);
                    }

                    //同意处理
                    lcs.BLL.Tools.DealAgree(dpid, person_id, reason);

                    Response.Redirect("ListBidResultSubmit.aspx");

                    #endregion

                }



            }
        }
        //审核未通过
        protected void btn_no_Click(object sender, EventArgs e)
        {
             if (Session["supplier_bidplan_order"] != null)
            {
                //插入中标情况表数据
                List<Maticsoft.Model.supplier_bidplan_order> l = Session["supplier_bidplan_order"] as List<Maticsoft.Model.supplier_bidplan_order>;

                if (l.Count > 0)
                {

                    //插入下一流程数据
                    int dpid = l[0].dpid.Value;

                    string reason = this.txt_reason.Text;

                    if (string.IsNullOrEmpty(reason))
                    {
                        reason = "否决";
                    }


                    int person_id = 0;
                    if (Session["login"] != null)
                    {
                        DataSet ds = Session["login"] as DataSet;

                        person_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"]);
                    }

                    //返回上一步
                    lcs.BLL.Tools.DealDisagreeLast(dpid, person_id, reason);

                    Response.Redirect("ListBidResultSubmit.aspx");
                }
            }
        }
    }
}